import { Component, EditBox, Label, UITransform, _decorator } from "cc";
import CommonEvent from "../../events/CommonEvent";
import MovieClip from "./MovieClip";
const {ccclass,property} = _decorator
@ccclass
export default class Radio extends Component {
    @property(Label)
    private label:Label = null
    @property(Component)
    private radio:Component = null
    @property(EditBox)
    private editBox:EditBox = null
    protected onLoad(): void {
        this.editBox.node.active=false
    }
    protected onEnable(): void {
        this.node.on('click',this.onClick,this)
    }
    protected onDisable(): void {
        this.node.off('click',this.onClick,this)
    }
    private onClick(e)
    {
        this.node.dispatchEvent(new CommonEvent(CommonEvent.RADIO_ITEM_SELECT,{value:this.label.string},true))
    }
    set selected(value:boolean)
    {
        const mc=this.radio.getComponent(MovieClip)
        mc.gotoAndStop(value?1:0)
    }
    set enableEdit(value:boolean)
    {
        const uit=this.node.getComponent(UITransform)
        if(value){
            uit.setContentSize(uit.width,100)
        }else{
            uit.setContentSize(uit.width,50)
        }
        this.editBox.node.active=value
    }
    set value(value:string)
    {
        this.label.string=value
    }
    get value():string
    {
        if(this.editBox.node.active){
            return this.editBox.string
        }
        return this.label.string
    }
}